<template>
  <div
    @wheel.stop="handleScroll"
    class="jy-style-height Cultural-box"
    :style="{
      'background-image': `url(${publicUrls + 'free/style7/publicStyle7Bg.png' + '?imageView2/3/format/webp'})`,
    }"
  >
    <div class="copyright-heard">
      <img class="backHome" @click="blankHome" :src="publicUrls + 'free/style7/backHome.png'" alt="" />
      <div class="heard-title">
        <span>文创商品</span>
      </div>
    </div>
    <ScrollBoxCom color="rgba(50, 43, 37, 1)"  :tabbmScroll="getTabmComputed" v-if="Scrollwidth" :byid="98676" :width="getScrollWidth">
      <template #solidBorderExcon>
        <div
          class="right-scroll"
          ref="scrollBox"
          :style="list?.length <= 4 && { justifyContent: 'center', paddingLeft: '0px' }"
        >
          <div class="is-null" v-if="list.length === 0 && !loading"><span>暂无文创商品</span></div>
          <!-- <div class="is-null" v-if="list.length === 0 && !loading"><span>暂无文创商品</span></div> -->
          <div class="item-parent" v-for="(item, index) in list" :key="item.id">
            <div class="item" :class="{ 'item-1': index === 0, 'item-max': index === list.length - 1 }">
              <div
                class="item-img-box"
                @click="pathLink(item.url)"
                :style="{
                  'background-image': `url(${
                    publicUrls + 'free/style7/culturalImgStyle7Bg.png' + '?imageView2/3/format/webp'
                  })`,
                }"
              >
                <img
                  class="item-img t-image t-image--fit-cover t-image--position-center item-img-null"
                  v-if="!item.coverUrl"
                  src="http://101.34.143.36:8890/api/image/387939155165253"
                  alt=""
                />
                <img
                  class="item-img t-image t-image--fit-cover t-image--position-center"
                  v-else
                  :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/3/format/webp')"
                  alt=""
                />
              </div>
              <p class="item-name">{{ item.name }}</p>
              <div class="item-btm">
                <span class="item-title3" v-if="item.price">参考价</span>
                <span class="item-title1" v-if="item.price">￥</span>
                <span class="item-title2" v-if="item.price">{{ item.price }}</span>

                <span class="item-title4" v-if="!item.price">暂无价格</span>
              </div>
            </div>
          </div>
        </div>
      </template>
      <template #solidBorderExbar>
        <div class="solidBorder-child"></div>
      </template>
    </ScrollBoxCom>
    <a :href="doorUrl" target="blank" class="logo-box">
      <i class="iconfonts">&#xe6dd;</i>
      <span>· 永不落幕的展览与展示平台</span>
    </a>
  </div>
  <MenuNavigation />
</template> 

<script lang="ts">
export default defineComponent({
  name: 'style7',
});
</script>

<script setup lang="ts">
// @ts-nocheck 
import MenuNavigation from '@/freeComponents/menuNavigation/index.vue';
import { publicUrls, doorUrl } from '@/utils/minxin';
import { goodsList } from '@/api/goods/goods';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import ScrollBoxCom from '../scrollBox7.vue';
import { ref, watch, reactive, nextTick, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';

const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 100,
});
const topShow = ref(false);
const scrollBox = ref(null);
const percentage = ref(0);
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const store = useProjectStore();
const Scrollwidth = ref();
const router = useRouter();
const route = useRoute();
const Description = ref('');
const init = async () => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await goodsList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    list.value = list.value.concat(res.data.data);
    // list.value = [];
    loading.value = false;
  } catch {
    loading.value = false;
  }
};
init();

let viewportwidth = window.innerWidth;
Scrollwidth.value = (viewportwidth / 900) * 620;

const getScrollWidth = computed(() => {
  let widths = (window.innerWidth / 900) * 620;
  return widths;
});
const getTabmComputed = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 60;
  return heights;
});
const handleScroll = (event) => {
  event.preventDefault(); // 阻止默认滚动行为
  const { deltaY } = event;

  // 获取滚动内容的 DOM 元素
  const contentEl = scrollBox.value;

  // 将滚动盒子向前滚动
  contentEl.scrollLeft += deltaY;
  if (contentEl.scrollWidth > contentEl.clientWidth) {
    if (
      contentEl.scrollWidth < contentEl.scrollLeft + contentEl.clientWidth + 100 &&
      !loading.value &&
      list.value.length < total.value
    ) {
      parmas.pageNo = parmas.pageNo + 1;
      init();
    }
    nextTick(() => {
      const { scrollLeft, clientWidth, scrollWidth } = scrollBox.value;
      if (scrollLeft > 100) {
        topShow.value = true;
      }
      if (scrollLeft < 100) {
        topShow.value = false;
      }
      const newScrollPercentage = Math.floor((scrollLeft / (scrollWidth - clientWidth)) * 100);
      percentage.value = newScrollPercentage == 99 ? 100 : newScrollPercentage;
    });
  }
};
const emitTop = () => {
  //点击回到列表最左侧
  scrollBox.value.scrollLeft = 0;
  percentage.value = 0;
  topShow.value = false;
};
const pathLink = (url?: string) => {
  if (!url) {
    return;
  }
  window.open(url, '_blank');
};
const blankHome = () => {
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
</script>

<style scoped lang="less">
.Cultural-box {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  padding: 50px 0;
  padding-bottom: 0px;
  background-size: 100% 100%;
}
.copyright-heard {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
  margin-bottom: 32px;
  padding: 0 120px;
  .heard-title {
    color: rgba(112, 157, 134, 1);
    font-family: 'SourceHanSerifCN-Bold';
    font-size: 28px;
    line-height: 56px;
    text-align: center;
  }
  .backHome {
    cursor: pointer;
    width: 48px;
    height: 48px;
    margin-left: 0 !important;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 80px;
  }
}
.right-scroll {
  display: flex;
  width: 100%;
  padding-top: 12px;
  min-height: 368px;
  padding-left: 0px;
}
:deep(.unit-exbi-remarks-info-remarks) {
  min-height: 368px;
  padding-top: 0 !important;
}
:deep(.solid-box-parent) {
  margin-top: 32px;
  right: 60px;
}
.right-scroll::-webkit-scrollbar {
  display: none;
}
.item-parent {
  margin-right: 40px;
  height: 450px;
}
.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 310px;
  height: 450px;
}

.item-img-box {
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 310px;
  height: 360px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.item-img {
  position: relative;
  z-index: 30;
  width: 280px;
  height: 330px;
  object-fit: cover;
  transition: all 0.3s;
}
.item-img-null {
  object-fit: contain;
}
.item-name {
  width: 100%;
  font-family: SourceHanSerifCN-Bold !important;
  font-size: 18px;
  color: rgba(51, 51, 51, 1);
  line-height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 16px;
  margin-bottom: 4px;
  text-indent: 0rem !important;
}
.item-btm {
  width: 100%;
  display: flex;
  align-items: baseline;
}
.item-title1 {  
  font-family: 'SourceHanSerifCN-Bold';
  font-size: 22px;  
  color: rgba(51, 51, 51, 1); 
  line-height: 34px;
  margin-left: 2px;  
} 
.item-title2 {
  font-family: 'SourceHanSerifCN-Bold';
  font-size: 22px;
  color: rgba(51, 51, 51, 1);
  line-height: 34px;
}

.item-title3 {
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 12px;
  color: rgba(51, 51, 51, 0.5);
  line-height: 24px;
}
.item-title4 {
  font-family: 'SourceMedium';
  font-weight: 400;
  font-size: 16px;
  color: rgba(51, 51, 51, 1);
  line-height: 34px;
}
.solidBorder-child {
  width: 100%;
  height: 1px;
  background: rgba(156, 180, 158, 0.6);
  border-radius: 2px;
}
:deep(.templatestyle1-scroll-box-tumb) { 
  display: flex;
  align-items: center; 
  top: -4px;
  .scrollBar {
    width: 60px;
    height: 5px;
    background: rgba(156, 180, 158, 1);
    border-radius: 4px;
    box-shadow: none;
  }
}
.is-null {
  margin: 0 auto;
  // margin-left: -100px;
  margin-top: 200px;
  text-align: center;
  span {
    font-size: 20px;
    line-height: 32px;
    color: #56677b;
    opacity: 0.5;
  }
}
.item-max {
  margin-right: 40px;
}
:deep(.unit-exbit-null-remarks-info) {
  margin-left: 120px;
  margin-right: 0px;
  width: auto;
}
:deep(.right-scroll) {
  padding-right: 0px !important;
}
@media screen and (min-width: 2150px) {
  :deep(.unit-exbit-null-remarks-info) {
    margin-left: 120px;
    margin-right: 50px;
    width: auto;
  }
}
@media screen and (max-width: 900px) {
  :deep(.unit-exbit-null-remarks-info) {
    margin-left: 120px;
    margin-right: 50px;
    width: auto;
  }
}
.logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  position: absolute;
  bottom: 0px;
  left: 0px;
  .iconfonts {
    font-size: 25px;
    line-height: 32px;
    color: rgba(156, 180, 158, 1);
    margin-top: 3px;
  }
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 22.4px;
    text-align: left;
    color: rgba(156, 180, 158, 1);
    margin-left: 8px;
  }
}
</style>